﻿using System.Collections;
using System.Collections.Generic;
using System.Web.Services;
using System.Web.Script.Services;
using EasyLibrary.AR;
using EasyLibrary.AR.Services;

namespace EasyFrota_Mobile.Servicos
{
    /// <summary>
    /// Summary description for localveiculo
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
     [System.Web.Script.Services.ScriptService]
    public class localveiculo : System.Web.Services.WebService
    {

        

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public List<Hashtable> ObterCoordenadasDaLocalidade(int IdViatura)
        {
           List<Hashtable> d = new List<Hashtable>();
           //BDconn dbAccess = new BDconn();
            ActiveRecord ar=null;
            var linha = Gps.GetLocalizacaoActual(IdViatura);
          //  var linha = ar.executeCommandOnDataSet(" SELECT Viaturas.IDViaturas, Viaturas.matricula, TiposViatura.TipoViatura, Viaturas.Longitude,                                                                        Viaturas.Latitude FROM  Viaturas INNER JOIN TiposViatura ON Viaturas.RefIDTiposViatura =                                                                        TiposViatura.IDTiposViatura WHERE (Viaturas.IDViaturas = " + IdViatura + ")");
            string l;
            for (int i = 0; i < linha.Count; i++)
            {
                if(linha[i].Ligado.ToString()=="false")
                {
                    l = "Sim";
                } else
                {
                    l = "Não";
                }
                d.Add(new Hashtable { { "IdViatura", linha[i].IdViatura.ToString() }, 
                                        { "Matricula", linha[i].Matricula.ToString() },
                                        { "TipoViatura", linha[i].RefIdTipoViatura.ToString() },
                                         { "Longitude", linha[i].Longitude.ToString().Replace(',','.') },
                                          { "Latitude", linha[i].Latitude.ToString().Replace(',','.') },
                                              { "Ligado", l.ToString()},
                                        });
            }
            return d;
            
        }
    }
}
